#ifndef ANALOG_SAMPLE_H
#define ANALOG_SAMPLE_H
#include "AnalogIn.h"
#include "CircularBuffer.h"
#include "Scheduler.h"

class AnalogSample : public Scheduler
{
public:
    AnalogSample(PinName _a0,PinName _a1,PinName _a2,PinName _a3);
    ~AnalogSample();

    void read();
    int a0_buffer();
    int a1_buffer();
    int a2_buffer();
    int a3_buffer();

    void set_a0_enabled(bool enable);
    void set_a1_enabled(bool enable);
    void set_a2_enabled(bool enable);
    void set_a3_enabled(bool enable);
    
    void schedule() override;
    void update() override;
    void cleanup()override;
private:
    AnalogIn _a0;
    AnalogIn _a1;
    AnalogIn _a2;
    AnalogIn _a3;

    volatile int _last_a0;
    volatile int _last_a1;
    volatile int _last_a2;
    volatile int _last_a3;

    CircularBuffer<int,3> _cb_a0;
    CircularBuffer<int,3> _cb_a1;
    CircularBuffer<int,3> _cb_a2;
    CircularBuffer<int,3> _cb_a3;

    volatile uint8_t _sw;
    volatile bool _need_update;

    int _enable_a0;
    int _enable_a1;
    int _enable_a2;
    int _enable_a3;
};

#endif